home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / tbl_create.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  8.5 KB  |  254 lines

  1. <?php
  2. /* $Id: tbl_create.php,v 1.39 2003/07/19 12:02:26 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Get some core libraries
  8.  */
  9. require('./libraries/grab_globals.lib.php');
  10. $js_to_run = 'functions.js';
  11. require('./header.inc.php');
  12.  
  13. // Check parameters
  14.  
  15. if (!defined('PMA_COMMON_LIB_INCLUDED')) {
  16.     include('./libraries/common.lib.php');
  17. }
  18.  
  19. PMA_checkParameters(array('db', 'table'));
  20.  
  21. /**
  22.  * Defines the url to return to in case of error in a sql statement
  23.  */
  24. $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
  25.  
  26.  
  27. /**
  28.  * Selects the database to work with
  29.  */
  30. PMA_mysql_select_db($db);
  31.  
  32.  
  33. /**
  34.  * The form used to define the structure of the table has been submitted
  35.  */
  36. $abort = false;
  37. if (isset($submit)) {
  38.     $sql_query = $query_cpy = '';
  39.  
  40.     // Transforms the radio button field_key into 3 arrays
  41.     $field_cnt = count($field_name);
  42.     for ($i = 0; $i < $field_cnt; ++$i) {
  43.         if (isset(${'field_key_' . $i})) {
  44.             if (${'field_key_' . $i} == 'primary_' . $i) {
  45.                 $field_primary[] = $i;
  46.             }
  47.             if (${'field_key_' . $i} == 'index_' . $i) {
  48.                 $field_index[]   = $i;
  49.             }
  50.             if (${'field_key_' . $i} == 'unique_' . $i) {
  51.                 $field_unique[]  = $i;
  52.             }
  53.         } // end if
  54.     } // end for
  55.     // Builds the fields creation statements
  56.     for ($i = 0; $i < $field_cnt; $i++) {
  57.         if (empty($field_name[$i])) {
  58.             continue;
  59.         }
  60.         if (PMA_MYSQL_INT_VERSION < 32306) {
  61.             PMA_checkReservedWords($field_name[$i], $err_url);
  62.         }
  63.         $query = PMA_backquote($field_name[$i]) . ' ' . $field_type[$i];
  64.         if ($field_length[$i] != '') {
  65.             $query .= '(' . $field_length[$i] . ')';
  66.         }
  67.         if ($field_attribute[$i] != '') {
  68.             $query .= ' ' . $field_attribute[$i];
  69.         } else if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($field_charset[$i])) {
  70.             $query .= ' CHARACTER SET ' . $field_charset[$i];
  71.         }
  72.         if ($field_default[$i] != '') {
  73.             if (strtoupper($field_default[$i]) == 'NULL') {
  74.                 $query .= ' DEFAULT NULL';
  75.             } else {
  76.                 $query .= ' DEFAULT \'' . PMA_sqlAddslashes($field_default[$i]) . '\'';
  77.             }
  78.         }
  79.         if ($field_null[$i] != '') {
  80.             $query .= ' ' . $field_null[$i];
  81.         }
  82.         if ($field_extra[$i] != '') {
  83.             $query .= ' ' . $field_extra[$i];
  84.         }
  85.         $query .= ', ';
  86.         $sql_query .= $query;
  87.         $query_cpy .= "\n" . '  ' . $query;
  88.     } // end for
  89.     unset($field_cnt);
  90.     unset($query);
  91.     $sql_query = ereg_replace(', $', '', $sql_query);
  92.     $query_cpy = ereg_replace(', $', '', $query_cpy);
  93.  
  94.     // Builds the primary keys statements
  95.     $primary     = '';
  96.     $primary_cnt = (isset($field_primary) ? count($field_primary) : 0);
  97.     for ($i = 0; $i < $primary_cnt; $i++) {
  98.         $j = $field_primary[$i];
  99.         if (!empty($field_name[$j])) {
  100.             $primary .= PMA_backquote($field_name[$j]) . ', ';
  101.         }
  102.     } // end for
  103.     unset($primary_cnt);
  104.     $primary = ereg_replace(', $', '', $primary);
  105.     if (!empty($primary)) {
  106.         $sql_query .= ', PRIMARY KEY (' . $primary . ')';
  107.         $query_cpy .= ',' . "\n" . '  PRIMARY KEY (' . $primary . ')';
  108.     }
  109.     unset($primary);
  110.  
  111.     // Builds the indexes statements
  112.     $index     = '';
  113.     $index_cnt = (isset($field_index) ? count($field_index) : 0);
  114.     for ($i = 0;$i < $index_cnt; $i++) {
  115.         $j = $field_index[$i];
  116.         if (!empty($field_name[$j])) {
  117.             $index .= PMA_backquote($field_name[$j]) . ', ';
  118.         }
  119.     } // end for
  120.     unset($index_cnt);
  121.     $index = ereg_replace(', $', '', $index);
  122.     if (!empty($index)) {
  123.         $sql_query .= ', INDEX (' . $index . ')';
  124.         $query_cpy .= ',' . "\n" . '  INDEX (' . $index . ')';
  125.     }
  126.     unset($index);
  127.  
  128.     // Builds the uniques statements
  129.     $unique     = '';
  130.     $unique_cnt = (isset($field_unique) ? count($field_unique) : 0);
  131.     for ($i = 0; $i < $unique_cnt; $i++) {
  132.         $j = $field_unique[$i];
  133.         if (!empty($field_name[$j])) {
  134.            $unique .= PMA_backquote($field_name[$j]) . ', ';
  135.         }
  136.     } // end for
  137.     unset($unique_cnt);
  138.     $unique = ereg_replace(', $', '', $unique);
  139.     if (!empty($unique)) {
  140.         $sql_query .= ', UNIQUE (' . $unique . ')';
  141.         $query_cpy .= ',' . "\n" . '  UNIQUE (' . $unique . ')';
  142.     }
  143.     unset($unique);
  144.  
  145.     // Builds the fulltextes statements
  146.     $fulltext     = '';
  147.     $fulltext_cnt = (isset($field_fulltext) ? count($field_fulltext) : 0);
  148.     for ($i = 0; $i < $fulltext_cnt; $i++) {
  149.         $j = $field_fulltext[$i];
  150.         if (!empty($field_name[$j])) {
  151.            $fulltext .= PMA_backquote($field_name[$j]) . ', ';
  152.         }
  153.     } // end for
  154.  
  155.     $fulltext = ereg_replace(', $', '', $fulltext);
  156.     if (!empty($fulltext)) {
  157.         $sql_query .= ', FULLTEXT (' . $fulltext . ')';
  158.         $query_cpy .= ',' . "\n" . '  FULLTEXT (' . $fulltext . ')';
  159.     }
  160.     unset($fulltext);
  161.  
  162.     // Builds the 'create table' statement
  163.     $sql_query      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
  164.     $query_cpy      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';
  165.  
  166.     // Adds table type, character set and comments
  167.     if (!empty($tbl_type) && ($tbl_type != 'Default')) {
  168.         $sql_query .= ' TYPE = ' . $tbl_type;
  169.         $query_cpy .= "\n" . 'TYPE = ' . $tbl_type;
  170.     }
  171.     if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_charset)) {
  172.         $sql_query .= ' CHARACTER SET = ' . $tbl_charset;
  173.         $query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset;
  174.     }
  175.     if (PMA_MYSQL_INT_VERSION >= 32300 && !empty($comment)) {
  176.         $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
  177.         $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
  178.     }
  179.  
  180.     // Executes the query
  181.     $error_create = false;
  182.     $result    = PMA_mysql_query($sql_query) or $error_create = true;
  183.  
  184.     if ($error_create == false) {
  185.         $sql_query = $query_cpy . ';';
  186.         unset($query_cpy);
  187.         $message   = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
  188.  
  189.         // garvin: If comments were sent, enable relation stuff
  190.         require('./libraries/relation.lib.php');
  191.         require('./libraries/transformations.lib.php');
  192.  
  193.         $cfgRelation = PMA_getRelationsParam();
  194.  
  195.         // garvin: Update comment table, if a comment was set.
  196.         if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) {
  197.             @reset($field_comments);
  198.             while(list($fieldindex, $fieldcomment) = each($field_comments)) {
  199.                 PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment);
  200.             }
  201.         }
  202.  
  203.         // garvin: Update comment table for mime types [MIME]
  204.         if (isset($field_mimetype) && is_array($field_mimetype) && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfg['BrowseMIME']) {
  205.             @reset($field_mimetype);
  206.             while(list($fieldindex, $mimetype) = each($field_mimetype)) {
  207.                 PMA_setMIME($db, $table, $field_name[$fieldindex], $mimetype, $field_transformation[$fieldindex], $field_transformation_options[$fieldindex]);
  208.             }
  209.         }
  210.  
  211.         include('./' . $cfg['DefaultTabTable']);
  212.         $abort = TRUE;
  213.         exit();
  214.     } else {
  215.         PMA_mysqlDie('', '', '', $err_url, FALSE);
  216.         // garvin: An error happened while inserting/updating a table definition.
  217.         // to prevent total loss of that data, we embed the form once again.
  218.         // The variable $regenerate will be used to restore data in tbl_properties.inc.php
  219.         $num_fields = $orig_num_fields;
  220.         $regenerate = true;
  221.     }
  222. } // end do create table
  223.  
  224. /**
  225.  * Displays the form used to define the structure of the table
  226.  */
  227. if ($abort == FALSE) {
  228.     if (isset($num_fields)) {
  229.         $num_fields = intval($num_fields);
  230.     }
  231.     // No table name
  232.     if (!isset($table) || trim($table) == '') {
  233.         PMA_mysqlDie($strTableEmpty, '', '', $err_url);
  234.     }
  235.     // No valid number of fields
  236.     else if (empty($num_fields) || !is_int($num_fields)) {
  237.         PMA_mysqlDie($strFieldsEmpty, '', '', $err_url);
  238.     }
  239.     // Table name and number of fields are valid -> show the form
  240.     else {
  241.         if (PMA_MYSQL_INT_VERSION < 32306) {
  242.             PMA_checkReservedWords($table, $err_url);
  243.         }
  244.  
  245.         $action = 'tbl_create.php';
  246.         include('./tbl_properties.inc.php');
  247.         // Diplays the footer
  248.         echo "\n";
  249.         include('./footer.inc.php');
  250.    }
  251. }
  252.  
  253. ?>
  254.